﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompanyRatings.SQL.PerfTest.ConsoleApp.Repositories
{
    public class DSRSystemRepository
    {
        public string ConnectionString { get; set; }


        public DSRSystemRepository()
            : this(ConfigurationManager.ConnectionStrings["DSRSystem"].ConnectionString)
        {
        }

        public DSRSystemRepository(string connectionString)
        {
            this.ConnectionString = connectionString;
        }


        public List<WeightMatrix> GetWeightMatrices()
        {
            DataTable table = new DataTable();

            using (SqlConnection conn = new SqlConnection(this.ConnectionString))
            {
                using (SqlCommand comm = new SqlCommand("SELECT * FROM WeightMatrices ORDER BY Name", conn))
                {
                    comm.CommandTimeout = (int)TimeSpan.FromSeconds(60 * 60).TotalSeconds;

                    using (SqlDataAdapter adapter = new SqlDataAdapter(comm))
                    {
                        adapter.Fill(table);
                    }

                    //using (SqlDataReader reader = comm.ExecuteReader())
                    //{
                    //    // read results
                    //}
                }
            }

            List<WeightMatrix> weightMatrixLst = WeightMatrix.FromDataTable(table);
            return weightMatrixLst;
        }
    }
}
